package com.tencent.wxcloudrun.vo.response.store;

import com.tencent.wxcloudrun.domain.TStoreProd;
import com.tencent.wxcloudrun.domain.TStoreProdAttr;
import com.tencent.wxcloudrun.dto.StoreProdAttrReqDTO;
import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.Data;
import org.springframework.util.CollectionUtils;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @Author ZhaoZiYin
 * @Date 2025/4/22
 * @Description 查询商品详情请求出参
 */
@Data
@ApiModel(value = "StoreProdQueryResVo", description = "查询商品详情请求出参")
public class StoreProdQueryResVo {

    @ApiModelProperty("商品分类ID")
    private Long prodTypeId;

    @ApiModelProperty("商品名称")
    private String name;

    @ApiModelProperty("商品描述")
    private String content;

    @ApiModelProperty("商品图片列表")
    private String imgUrlList;

    @ApiModelProperty("商品状态 1-上架 2-下架")
    private Integer status;

    @ApiModelProperty("商品价格")
    private BigDecimal price;

    @ApiModelProperty("库存总数")
    private Integer totalStock;

    @ApiModelProperty("是否多选")
    private Integer multipleFlag;

    @ApiModelProperty("是否限购")
    private Integer limitFlag;

    @ApiModelProperty("限购最小数量")
    private Integer limitMinVol;

    @ApiModelProperty("限购最大数量")
    private Integer limitMaxVol;

    @ApiModelProperty("商品属性列表")
    private List<StoreProdAttrReqDTO> prodAttrList;

    public void build(TStoreProd storeProd, List<TStoreProdAttr> prodAttrList) {
        this.setProdTypeId(storeProd.getProdTypeId());
        this.setName(storeProd.getName());
        this.setContent(storeProd.getContent());
        this.setImgUrlList(storeProd.getImgUrlList());
        this.setStatus(storeProd.getStatus());
        this.setPrice(storeProd.getPrice());
        this.setTotalStock(storeProd.getTotalStock());
        this.setMultipleFlag(storeProd.getMultipleFlag());
        this.setLimitFlag(storeProd.getLimitFlag());
        this.setLimitMinVol(storeProd.getLimitMinVol());
        this.setLimitMaxVol(storeProd.getLimitMaxVol());
        if (!CollectionUtils.isEmpty(prodAttrList)) {
            List<StoreProdAttrReqDTO> prodAttrDTOList = getStoreProdAttrReqDTOList(prodAttrList);
            this.setProdAttrList(prodAttrDTOList);
        }
    }

    private List<StoreProdAttrReqDTO> getStoreProdAttrReqDTOList(List<TStoreProdAttr> prodAttrList) {
        List<StoreProdAttrReqDTO> prodAttrDTOList = new ArrayList<>(prodAttrList.size());
        for (TStoreProdAttr storeProdAttr : prodAttrList) {
            StoreProdAttrReqDTO reqDTO = new StoreProdAttrReqDTO();
            reqDTO.setProdAttrId(storeProdAttr.getId());
            reqDTO.setName(storeProdAttr.getName());
            reqDTO.setValue(storeProdAttr.getValue());
            reqDTO.setStock(storeProdAttr.getStock());
            prodAttrDTOList.add(reqDTO);
        }
        return prodAttrDTOList;
    }

}
